<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="年度">
              <a-date-picker
                style="width: 100%"
                :open="yearShowOne"
                :default-value="moment(new Date(), 'YYYY')"
                @openChange="openChangeOne"
                @panelChange="panelChangeOne"
                mode="year"
                format="YYYY"
                type="date"
                v-model="queryParam.sbnd"
                suffix-icon=" "
                placeholder="年份"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="分组">
              <a-select v-model="queryParam.fzid" placeholder="请选择分组">
                <a-select-option v-for="(item, index) in fzlist" :key="index" :value="item.id">
                  {{ item.fs_fz_mc }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="成果编号">
              <a-input placeholder="请填写成果编号" v-model="queryParam.cxj_xmbh"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="成果名称">
              <a-input placeholder="请填写成果名称" v-model="queryParam.cxj_mc_zw"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" @click="exportpftj" style="margin-left: 8px">导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        class="j-table-force-nowrap"
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="pfqk" slot-scope="text, record">
          <span>{{ record.zjsl ? record.zjsl : '' }} {{ record.pfsl ? '(' + record.pfsl + ')' : '' }}</span>
        </template>
        <template slot="jscsdf" slot-scope="text, record">
          <span class="pointer pjf" @click="handlecsdf(record)">{{ record.jscsdf }}</span>
        </template>
        <template slot="pjf" slot-scope="text, record">
          <span class="pointer pjf" @click="handlepjf(record)">{{ record.pjf }}</span>
        </template>
        <template slot="zdf" slot-scope="text, record">
          <span class="">{{ record.zdf }}</span>
        </template>
        <template slot="znpm" slot-scope="text, record">
          <span>{{ record.pm ? record.pm : '' }} / {{ record.xmsl }}</span>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <cxj-jscs-fz-xm-modal ref="modalForm" @ok="modalFormOk"></cxj-jscs-fz-xm-modal>
    <cxj-jscs-fz-xm-pftj ref="modalForm" :expertFlag="expertFlagcs" :cxj_cxj_id="cxj_cxj_id" :flid="flid"></cxj-jscs-fz-xm-pftj>
    <cxj-fs-fz-xm-pftj ref="modalForm" :expertFlag="expertFlag" :cxj_cxj_id="cxj_cxj_id" :flid="flid"></cxj-fs-fz-xm-pftj>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import CxjJscsFzXmModal from './modules/CxjJscsFzXmModal'
import CxjFsFzXmPftj from './modules/CxjFsFzXmPftj'
import CxjJscsFzXmPftj from './modules/CxjJscsFzXmPftj'
import moment from 'moment'
import { mixinDevice } from '@/utils/mixin'
import { filterObj } from '@/utils/util';
import {
  getAction,
  zfTj_Zg,
  zfTj_export_zg
} from "@/api/manage"
export default {
  name: 'CxjFsPftjZg',
  mixins: [ mixinDevice ],
  components: {
    CxjJscsFzXmModal,
    CxjFsFzXmPftj,
    CxjJscsFzXmPftj
  },
  data() {
    return {
      description: '总分统计 - 职工类',
      flid: 61,
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '成果编号',
          align: "center",
          dataIndex: 'cxj_xmbh'
        },
        {
          title: '成果名称',
          align: "center",
          dataIndex: 'cxj_mc_zw'
        },
        {
          title: '申报单位',
          align: "center",
          dataIndex: 'sbdw_qymc'
        },
        {
          title: '所属集团',
          align: "center",
          dataIndex: 'ssjt'
        },
        {
          title: '成果类别',
          align: "center",
          dataIndex: 'fl_mc'
        },
        {
          title: '复审分组',
          align: "center",
          dataIndex: 'fs_fz_mc'
        },
        {
          title: '初审得分',
          align: "center",
          dataIndex: 'jscsdf',
          scopedSlots: { customRender: 'jscsdf' }
        },
        {
          title: '复审得分',
          align: "center",
          dataIndex: 'pjf',
          scopedSlots: { customRender: 'pjf' }
        },
        {
          title: '总得分',
          align: "center",
          dataIndex: 'zdf',
          scopedSlots: { customRender: 'zdf' }
        },
        {
          title: '组内排序',
          align: "center",
          dataIndex: 'pm',
          scopedSlots: { customRender: 'znpm' }
        },
      ],
      url: {
        list: "/cxj/cxjJscsPfZg/jscsPfTj",
        cxjcs_fzlist: '/cxj/cxjFsFz/cxjfs_fzlist'
      },
      expertFlag: false,
      expertFlagcs: false,
      exportLoading: false,
      cxj_cxj_id: '',
      fzlist: [],
      /* 列表参数开始 */
      queryParam: {},
      dictOptions: {},
      superFieldList: [],
      fileStatus: "",
      selectedRowKeys: [],
      selectionRows: [],
      loading: false,
      isorter: {
        column: 'createTime',
        order: 'desc',
      },
      dataSource: [],
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      /* 列表参数结束 */
      /* 年份参数开始 */
      yearShowOne: false,
      sbnd: moment(new Date()).format('YYYY'),
      /* 年份参数结束 */
    }
  },
  created() {
    this.$set(this.dictOptions, 'isValid', [{ text: '是', value: 'Y' }, { text: '否', value: 'N' }])
    this.getSuperFieldList();
    this.getcxjcs_fzlist();
    this.loadData();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    moment,
    getcxjcs_fzlist() {
      getAction(this.url.cxjcs_fzlist, { flid: this.flid }).then(res => {
        if (res.success) {
          this.fzlist = res.result.records;
        }
      })
    },
    /* 获取列表固定格式开始 */
    getQueryField() {
      //TODO 字段权限控制
      var str = "id,";
      this.columns.forEach(function (value) {
        str += "," + value.dataIndex;
      });
      return str;
    },
    // 获取分组项目
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();//查询条件
      this.loading = true;
      // 分组id
      zfTj_Zg(params).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result;
          if (res.result.total) {
            this.ipagination.total = res.result.total;
          } else {
            this.ipagination.total = 0;
          }
          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
    },
    onClearSelected() {
      this.selectedRowKeys = [];
      this.selectionRows = [];
    },
    modalFormOk() {
      // 新增/修改 成功时，重载列表
      this.loadData();
      //清空列表选中
      this.onClearSelected()
    },
    handleTableChange(pagination, filters, sorter) {
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.ipagination = pagination;
      this.loadData();
    },
    getQueryParams() {
      //获取查询条件
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      this.queryParam.sbnd = this.sbnd;
      var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      return filterObj(param);
    },
    handleAdd: function () {
      this.$refs.modalForm.add();
      this.$refs.modalForm.title = "新增";
      this.$refs.modalForm.disableSubmit = false;
    },
    handleEdit: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "编辑";
      this.$refs.modalForm.disableSubmit = false;
    },
    handlecsdf(record) {
      this.expertFlagcs = !this.expertFlagcs;
      this.cxj_cxj_id = record.cxj_cxj_id;
    },
    handlepjf(record) {
      this.expertFlag = !this.expertFlag;
      this.cxj_cxj_id = record.cxj_cxj_id;
    },
    searchQuery() {
      this.loadData(1);
    },
    searchReset() {
      this.queryParam = {};
      this.sbnd = moment(new Date()).format('YYYY');
      this.queryParam.sbnd = this.sbnd;
      this.loadData(1);
    },
    exportpftj() {
      let self = this;
      let data = {
        sbnd: this.queryParam.sbnd,
        cxj_mc_zw: this.queryParam.cxj_mc_zw,
        cxj_xmbh: this.queryParam.cxj_xmbh,
        fzid: this.queryParam.fzid
      }
      zfTj_export_zg(data).then(res => {
        self.downfn('总分评分统计表-职工类', res);
      })
    },
    downfn(name, res) {
      const _res = res;
      let blob = new Blob([_res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
      let downloadElement = document.createElement("a");
      let href = window.URL.createObjectURL(blob); //创建下载的链接
      downloadElement.href = href;
      downloadElement.download = name; //下载后文件名
      document.body.appendChild(downloadElement);
      downloadElement.click(); //点击下载
      document.body.removeChild(downloadElement); //下载完成移除元素
      window.URL.revokeObjectURL(href); //释放掉blob对象
    },
    /* 获取列表固定格式结束 */
    /* 年份控制开始 */
    openChangeOne(status) {
      //status是打开或关闭的状态
      if (status) {
        this.yearShowOne = true;
      }
    },
    // 得到年份选择器的值
    panelChangeOne(value) {
      // params.sbnd = value;
      this.sbnd = moment(value).format('YYYY');
      this.queryParam.sbnd = this.sbnd;
      this.yearShowOne = false
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'cxjJscsFzId', text: '技术初审分组ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'cxjCxjId', text: '项目ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shijian', text: '年度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bz1', text: '备注1', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bz2', text: '备注2', dictCode: '' })
      fieldList.push({ type: 'switch', value: 'isValid', text: '是否有效' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.pjf {
  border-bottom: 1px solid #F83F3D;
  color: #F83F3D;
}
</style>